package com.bkq.viettravel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import bkq.viettravel.bll.FavoriteBLL;
import bkq.viettravel.bll.TravelBLL;
import bkq.viettravel.dto.FavoriteDTO;
import bkq.viettravel.dto.TravelDTO;



import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;


/*
 * author: Hung
 */
public class InformationTravelActivity extends Activity {
    /** Called when the activity is first created. */
	 //lap array list de luu tru danh sach cac thong tin can nhap vao cho list
	private ArrayList<String> postname= new ArrayList<String>();
	 private ArrayList<String> postcomment= new ArrayList<String>();
	 private int idTravel = 0;
	 TravelBLL travelBll = new TravelBLL(this);
     TravelDTO travel = null;
     
     FavoriteBLL favoriteBll = new FavoriteBLL(this);
     FavoriteDTO favorite = new FavoriteDTO();
	
	 //list
	 public final static String ITEM_POSTNAME = "postname";
	 public final static String ITEM_POSTCOMMENT = "postcomment";
	 public Map<String,String> createItem(String postname, String postcomment) {
	 Map<String,String> item = new HashMap<String,String>();
	 item.put(ITEM_POSTNAME, postname);
	 item.put(ITEM_POSTCOMMENT, postcomment);

	 return item;
	 }
	 
	 
	View lnlayout;
	ImageButton option=null, back=null, add_favorites=null, home=null, favorites=null, plant=null, infor= null;
	ImageView add_comment=null;
	Button hinhanh=null, dv_luhanh=null, chiduong=null;
	LoaderImageView img = null;
	TextView inforTravel = null;
	int option_selected=0;
	ListView listcomment;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.information_travel);
        lnlayout= (View) findViewById(R.id.ln_layout);
        hinhanh = (Button) findViewById(R.id.information_travel_list_option_hinhanh);
        dv_luhanh= (Button) findViewById(R.id.information_travel_list_option_luhang);
        chiduong= (Button) findViewById(R.id.information_travel_list_option_chiduong);
        option = (ImageButton) findViewById(R.id.information_travel_btn_opition);
        add_favorites= (ImageButton) findViewById(R.id.information_travel_btn_add_favorites);
        back = (ImageButton) findViewById(R.id.information_travel_btn_back);
        add_comment= (ImageView) findViewById(R.id.information_travel_btn_add_comment);
        home = (ImageButton) findViewById(R.id.information_travel_home);
        favorites = (ImageButton) findViewById(R.id.information_travel_favourites);
        plant = (ImageButton) findViewById(R.id.information_travel_plant);
        infor = (ImageButton) findViewById(R.id.information_travel_information);
        
        img = (LoaderImageView) findViewById(R.id.information_travel_img_travel);
        inforTravel = (TextView) findViewById(R.id.information_travel_tv_introduce);
        
        
        /*
         * get Id from ListTravel Activity
        */
        
        Bundle extras = getIntent().getExtras();
        if(extras!= null)
        {
        	idTravel = extras.getInt("idTravel");
        	Log.d("IdTravel = ", "" + idTravel);
        }
        
		if(idTravel != 0)
        	travel = travelBll.getById(idTravel);
		img.setImageDrawable(travel.getImageIntroduce());
		inforTravel.setText(travel.getIntroduce());
        
        
        
        //top bar
        option.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(option_selected==0)
				{
					option.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_option_selected));
					lnlayout.setVisibility(View.VISIBLE);
					option_selected=1;
				}
				else 
				{
					option.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_option2));
					lnlayout.setVisibility(View.INVISIBLE);
					option_selected=0;
					chiduong.setTextColor(Color.WHITE);
					dv_luhanh.setTextColor(Color.WHITE);
					hinhanh.setTextColor(Color.WHITE);
				}
				
				
			}

        });
        
        back.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					back.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_back_selected));
					
				
				
			}

        });
        chiduong.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					chiduong.setTextColor(Color.GREEN);
					chiduong.setShadowLayer(90,5, 5, Color.WHITE);
					//Intent i = new Intent(InformationTravelActivity.this, VietTravelActivity.class);
					//startActivity(i);
				
				
			}

        });
        hinhanh.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					hinhanh.setTextColor(Color.GREEN);
					Intent i = new Intent(InformationTravelActivity.this, ListImage.class);
					i.putExtra("idTravel", idTravel);
					startActivity(i);
				
				
				
			}

        });
        dv_luhanh.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					dv_luhanh.setTextColor(Color.GREEN);
					Intent i = new Intent(InformationTravelActivity.this, TravelService.class);
					startActivity(i);
				
				
				
			}

        });
        
        add_favorites.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				
					
					
				
				
			}

        });
        
        add_comment.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					add_comment.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_camnhan_selected));
					
				
				
			}

        });
        
        // body
        listcomment = (ListView) findViewById(R.id.information_travel_list_comment);
        
        //bottom bar
        
        home.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					home.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_trangchinh_selected));
					Intent i = new Intent(InformationTravelActivity.this, VietTravelActivity.class);
					startActivity(i);
				
				
			}

        });
        

        favorites.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				favorites.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_uuthich_selected));
				Intent i = new Intent(InformationTravelActivity.this, FavoritesActivity.class);
				startActivity(i);	
				
				
			}

        });
        

        plant.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
					plant.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_kehoach_selected));
					Intent i = new Intent(InformationTravelActivity.this, Plan.class);
					startActivity(i);
				
				
			}

        });
        

        infor.setOnClickListener(new OnClickListener()
        {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				infor.setBackgroundDrawable( getApplicationContext().getResources().getDrawable(R.drawable.icon_thongtin_selected));
				/*Intent i = new Intent(InformationTravelActivity.this, FavoritesActivity.class);
				startActivity(i);	*/
				
				
			}

        });
      //Initialize variable
      		try{
      		list_initialize();
      		}
      		catch(Exception ex ) {
      			
      		}
        
    }

	private void list_initialize() {
		// TODO Auto-generated method stub
		
		//lay du lieu
		// Dữ liệu chỉ mang tính chất kiểm tra, sau khi xây dựng database sẻ xây dựng lại
		postname.add("Hung");
		postcomment.add("cho nay chac vui lam");
		postname.add("Hoa");
		postcomment.add("cung dc");
		postname.add("Vien");
		postcomment.add("rat te, di moi chan ma chang thay gi vui, lam dut doi dep ton may chuc ngan mua lai");
		postname.add("Hung");
		postcomment.add("cho nay chac vui lam");
		postname.add("Hoa");
		postcomment.add("cung dc");
		postname.add("Vien");
		postcomment.add("rat te, di moi chan ma chang thay gi vui, lam dut doi dep ton may chuc ngan mua lai");
		postname.add("Hung");
		postcomment.add("cho nay chac vui lam");
		postname.add("Hoa");
		postcomment.add("cung dc");
		postname.add("Vien");
		postcomment.add("rat te, di moi chan ma chang thay gi vui, lam dut doi dep ton may chuc ngan mua lai");
		postcomment.add("cho nay chac vui lam");
		postname.add("Hoa");
		postcomment.add("cung dc");
		postname.add("Vien");
		postcomment.add("rat te, di moi chan ma chang thay gi vui, lam dut doi dep ton may chuc ngan mua lai");
		postcomment.add("cho nay chac vui lam");
		postname.add("Hoa");
		postcomment.add("cung dc");
		postname.add("Vien");
		postcomment.add("rat te, di moi chan ma chang thay gi vui, lam dut doi dep ton may chuc ngan mua lai");
		postcomment.add("cho nay chac vui lam");
		postname.add("Hoa");
		postcomment.add("cung dc");
		postname.add("Vien");
		postcomment.add("rat te, di moi chan ma chang thay gi vui, lam dut doi dep ton may chuc ngan mua lai");
		
	
	//gan du lieu vua lay vao cac String va truyen vao adapter
	 String[] post_name=postname.toArray(new String[postname.size()]);
	 String[] post_comment=postcomment.toArray(new String[postcomment.size()]);
	 
	 listcomment.setAdapter(new CommentArrayAdapter(this, post_name,post_comment));
	 Ultility.setListViewHeightBasedOnChildren(listcomment);
     listcomment.setTextFilterEnabled(true);
	}
    
}


